<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 发送 AJAX请求</title>
    <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/axios/1.1.3/axios.js"></script>
</head>

<body>
    <button id="btn1">GET</button>
    <button id="btn2">POST</button>
    <button id="btn3">AJAX</button>

    <script>
       let btn1 = document.getElementById('btn1')
       let btn2 = document.getElementById('btn2')
       let btn3 = document.getElementById('btn3')

       axios.defaults.baseURL = 'http://localhost:8000'

       btn1.onclick = function () {
           axios({
               method: 'get',
               url: '/server',
               responseType: 'json',
               params:{
                   name: '小小',
                   status: '好看'
               }
           })
               .then(function (response) {
                   console.log(response.data)
               });
       }
       
       btn2.onclick = function () {
           // axios.post('http://localhost:8000/server', {
           //     name: 'admin',
           //     status: 'admin'
           // }
           // ).then(function (response) {
           //     console.log(response)
           // });
           axios({
               method: 'post',
               url: '/axios-server',
               responseType: 'json',
               data:{
                   name: '小小',
                   status: '好看'
               }
           })
           .then(function (response) {
               console.log(response)
           });
       }
    </script>
</body>

</html>